<template>
    <div class="confimDialogClass">
        <!-- 患者身份确认 -->
        <el-dialog title="" :visible.sync="confirmDialog.show" width="300px" :show-close="false" center
            :before-close="handleClose" @open="dialogOpendFn">

            <div class="content">

                <div class="row mb10  fw500 f14">患者身份确认</div>
                <div class="info clr_2b3">
                    <div class="info_top">
                        <div class=" f18 fw500">
                            <span class="mr5">{{ confirmDialog?.patientData?.PatientName }}</span>
                            <span class="mr5">{{ confirmDialog?.patientData?.PatientSex }}</span>
                            <span class="mr5">{{ confirmDialog?.patientData?.PAge }}</span>
                        </div>
                        <div class="mt5 fw500 lh25">检查号：{{ confirmDialog?.patientData?.AccessionNumber }}</div>
                        <div class="mt5 fw500 lh25">病历号：{{ confirmDialog?.patientData?.MedrecNo }}</div>
                        <div class="mt5 fw500 lh25">签到时间：{{ confirmDialog?.patientData?.MedrecNo }}</div>
                        <div class="mt5 fw500 lh25">检查机房：{{ confirmDialog?.patientData?.ExamRoom }}</div>
                        <div class="mt5 fw500 lh25">是否增强：{{ confirmDialog?.patientData?.IsEnhancement == 1 ?'是':'否' }}</div>
                        <div class=" mt5 mb5 f14 fw500 lh25">{{ confirmDialog?.patientData?.ExamType }}|{{
                            confirmDialog?.patientData?.AllExamItems }}|{{ confirmDialog?.patientData?.ExamBodyPart }}</div>


                    </div>
                    <div class="info_bottom">
                        <div class="w100 number_input  bg_fff" v-if="confirmSate == 0">
                            <el-input ref="ruleDesc" clearable placeholder="请扫描" autofocus v-model="scanNumber" @keydown.enter.native="handleMatchFn"></el-input>
                        </div>
                        <div class="w100 number_input  bg_fff row clr_1cb fw500" v-if="confirmSate == 1">
                            <img :height="25" src="../../../assets/images/dialog/success.png" alt=""><span
                                class="lh25 ml10">患者身份确认成功</span>
                        </div>
                        <div class="w100 number_input  bg_fff row clr_ef8900 fw500" v-if="confirmSate == 2">
                            <img :height="25" src="../../../assets/images/dialog/confirm.png" alt=""><span
                                class="lh25 ml10">手工核对成功</span>
                        </div>
                        <div class="w100 number_input  bg_fff row clr_ff6 fw500" v-if="confirmSate == 3">
                            <img :height="25" src="../../../assets/images/dialog/failure.png" alt=""><span
                                class="lh25 ml10">患者身份确认失败</span>
                        </div>
                    </div>
                </div>


            </div>
            <span slot="footer" class="dialog-footer">

                <el-button :class="{ longWidth: confirmSate != 0 }" @click="handleClose">关 闭</el-button>
                <el-button v-if="confirmSate == 0" type="primary" @click="handleSure">手工核对</el-button>
            </span>
        </el-dialog>


    </div>
</template>

<script>
// import { mapGetters } from 'vuex';
import store from '@/store'

import {
    SaveScreenCheckMT,
} from '@/api/user'
export default {
    data() {
        return {
            scanNumber: '',
            confirmSate: 0,//0 初始状态 1成功 2手工核对 3失败
            userInfo: {},
            checkData: {
                UserID: "",
                UserName: "",
                PatientName: "",
                AccessionNumber: "",
                CheckResults: "",
                CheckType: "",
                HospitalId: "",
                DepartmentId: ""
            }
        };
    },
    props: ['confirmDialog','activeName'],
    computed: {
        // ...mapGetters(['loginInfo']),

    },
    watch: {

        scanNumber: {
            // handler(val) {
            //     if (val) {
            //         if (val == this.confirmDialog?.patientData?.AccessionNumber
            //             || val == this.confirmDialog?.patientData?.MedrecNo) {
            //             //核对成功
            //             this.checkData.CheckResults = '1'
            //             this.confirmSate = 1
            //         } else {
            //             //核对失败
            //             this.checkData.CheckResults = '0'
            //             this.confirmSate = 3
            //         }

            //         this.saveResult()



            //     }
            // }
        },
        'confirmDialog': {
            handler(val) {
                if (val) {
                    // switch (val.patientData?.OrderState) {
                    //     case '已登记': this.confirmSate = 1; break;
                    //     case '未摄片': this.confirmSate = 0; break;
                    //     default: this.confirmSate = 0; break;
                    // }
                    this.checkData.AccessionNumber = val.patientData?.AccessionNumber
                    this.checkData.PatientName = val.patientData?.PatientName
                    // this.checkData.CheckType = val.patientData?.ExamType  //暂时不传

                }

            },
            immediate: true,
        },
    },
    mounted() {
        this.loginInfo = store.getters.loginInfo
        this.userInfo = JSON.parse(this.loginInfo)

        this.checkData.CheckType = this.activeName
        this.checkData.UserID = this.userInfo.UserId
        this.checkData.UserName = this.userInfo.UserName
        this.checkData.HospitalId = this.userInfo.HospitalId
        this.checkData.DepartmentId = this.userInfo.DepartmentId
        this.$nextTick(() => {
            this.$refs?.ruleDesc?.focus()

        })
    },
    methods: {
        handleMatchFn(){
            
            if (this.scanNumber == this.confirmDialog?.patientData?.AccessionNumber
                        || this.scanNumber == this.confirmDialog?.patientData?.MedrecNo
                        || this.scanNumber == this.confirmDialog?.patientData?.HisKeyNo) {
                        //核对成功
                        this.checkData.CheckResults = '1'
                        this.confirmSate = 1
                    } else {
                        //核对失败
                        this.checkData.CheckResults = '0'
                        this.confirmSate = 3
                    }

                    this.saveResult()
        },
        dialogOpendFn() {
            this.$nextTick(() => {
                this.$refs?.ruleDesc?.focus()
            })
        },
        handleClose() {
            this.$emit('close')
        },
        handleSure() {
            this.checkData.CheckResults = '2'//手工核对   
            this.confirmSate = 2
            this.saveResult()

        },
        //记录扫描结果
         saveResult() {

            SaveScreenCheckMT(this.checkData)
            //核对记录成功后需要操作啥？

        }

    },
}
</script>
<style lang='less' scoped>
.confimDialogClass {
    ::v-deep .el-dialog {
        border-radius: 10px;
        // margin-left: 12.5px;
    }

    ::v-deep .el-dialog--center .el-dialog__body {
        padding: 0 15px 15px 15px;
        border-radius: 10px 10px 0 0;
        // border: ;
    }

    .content {
        padding-top: 10px;
    }

    ::v-deep .el-dialog__header {
        display: none;
    }

    .info {
        background-color: #F5F7FA;
        border-radius: 10px;

    }

    ::v-deep .el-dialog__footer {
        padding: 0 0 10px 0;
    }

    .dialog-footer {
        .el-button {
            width: 125px;
        }

        .longWidth {
            width: 270px;

        }

        .el-button--default {
            color: #1C8BE4;
        }
    }

    .info_top {
        background-color: #EBEEF5;
        padding: 15px;
        border-radius: 10px;
    }

    .info_bottom {
        background-color: #F5F7FA;
        padding: 5px 10px;
    }

    .number_input {
        padding: 10px;

        ::v-deep .el-input__inner {
            text-align: center;
            width: calc(100% - 20px);
            border: 1px solid #DCDFE6;
        }

        ::v-deep .el-input__suffix {
            right: 25px;
        }
    }
}
</style>